
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Tama_Chan.Utils;


namespace Tama_Chan.ParticleEngine_ns
{
   public class ScalingParticle : IParticle
   {
      public bool IsDead { get; set; }
      public long CreationTime { get; set; }
      public bool IsActivated { get; set; }
      public long ActivationDelay { get; set; }
      public long ActivationTime { get; set; }
      public SpriteBatch SpriteBatch { get; set; }
      public Texture2D Texture { get; set; }
      public Vector2 Position { get; set; }
      public Vector2 Velocity { get; set; }
      public Color Color { get; set; }
      public float Scale { get; set; }
      public float ScaleDelta { get; set; }
      public float ScaleLimit { get; set; }
      public bool IsExpanding { get; set; }
      public float Depth { get; set; }


      public ScalingParticle(SpriteBatch spriteBatch,
                             long creationTime,
                             long activationDelay,
                             Texture2D texture,
                             Vector2 position,
                             Vector2 velocity,
                             Color color,
                             float scale,
                             float scaleDelta,
                             float scaleLimit,
                             bool isExpanding,
                             float depth)
      {
         IsDead = false;
         CreationTime = creationTime;
         IsActivated = (activationDelay == 0);
         SpriteBatch = spriteBatch;
         ActivationDelay = activationDelay;
         Texture = texture;
         Position = position;
         Velocity = velocity;
         Color = color;
         Scale = scale;
         ScaleDelta = scaleDelta;
         ScaleLimit = scaleLimit;
         IsExpanding = isExpanding;
         Depth = depth;
      }


      public void Update(GameTime gameTime)
      {
         if(!IsActivated)
         {
            ActivationDelay -= gameTime.ElapsedGameTime.Ticks;
            IsActivated = ActivationDelay <= 0;
            return;
         }

         float scale = Scale;
         if(TransformUtils.GetScale(ref scale, gameTime, ScaleDelta, IsExpanding, ScaleLimit))
         {
            IsDead = true;
         }
         else
         {
            Scale = scale;
         }
      }


      public void Draw()
      {
         SpriteBatch.Draw(Texture,            // Texture
                          Position,           // Position
                          null,               // Source Rectangle
                          Color,              // Color
                          0f,                 // Rotation
                          new Vector2(Texture.Width/2f, Texture.Height/2f), // Origin
                          Scale,              // Current Scale
                          SpriteEffects.None, // Mirroring options
                          Depth);             // z-depth
      }

   }
}
